package inherit.dao;

import inherit.AbstractPerson;
import inherit.Department;
import util.HibernateUtil;

//import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
//import org.hibernate.criterion.Expression;

public class InheritDAOBean {

	public boolean doInsertOnePersonInfo(AbstractPerson onePerson)
	{
		Session session = null;
		Transaction tx = null;
		
		try {
			session = HibernateUtil.currentSession();
			tx = session.beginTransaction();
			session.save(onePerson);
			tx.commit();
		}catch(HibernateException he) {
			if(tx!=null)
			{
				tx.rollback();
			}
			throw he;
		}finally {
			HibernateUtil.closeSession();
		}
		return true;
	}
	
	public boolean doInsertOneDeptInfo(Department oneDep)
	{
		Session session = null;
		Transaction tx = null;
		
		try {
			session = HibernateUtil.currentSession();
			tx = session.beginTransaction();
			
			session.save(oneDep);
			tx.commit();
		}catch(HibernateException he) {
			if(tx!=null)
			{
				tx.rollback();
			}
			throw he;
		}finally {
			HibernateUtil.closeSession();
		}
		return true;
	}
}
